<!doctype html>
<html lang="en" class="fixed">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>权限编辑</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        ul, li, ol, li {
            list-style: none;
        }

        a {
            color: #000;
            text-decoration: none;
        }

        body {
            background: #F4F4F4;
        }

        .content {
            width: 1200px;
            margin: 0 auto;
            padding: 20px 30px;
            background: #fff;
        }

        .content .title .title-role p {

        }

        .content .title .title-role .title-btn {
            float: right;
            margin-top: -30px;
        }

        .content .title .title-role .title-btn button {
            padding: 6px 10px;
            margin: 0 4px;
            border-radius: 5px;
        }

        .content .title .title-role .title-btn button:nth-of-type(1) {
            background: #108EE9;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title .title-role .title-btn button:nth-of-type(2) {
            background: #108EE9;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title .title-role .title-btn button:nth-of-type(3) {
            background: #D75234;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title h2 {
            width: 100%;
            padding: 10px 20px;
            font-size: 12px;
            background: #f4f4f4;
            border-radius: 5px;
            margin-top: 24px;
        }

        .content .title p.name {
            font-size: 12px;
            margin-top: 20px;
        }

        .content .title p.name input {
            width: 180px;
            height: 24px;
            border: 1px #ccc solid;
            border-radius: 5px;
            text-indent: 10px;
        }

        .content .title p.name span {
            margin-left: 40px;
        }

        .content .module h3 {
            font-size: 12px;
            width: 100%;
            background: #f4f4f4;
            padding: 10px 20px;
            border-radius: 5px;
        }

        .content .module .module-content {
            margin-top: 30px;
            padding-right: 30px;
        }

        .content .module .module-content ul {
            display: inline-block;
            border: 1px #eee solid;
        }

        .content .module .module-content ul li {
            border-bottom: 1px #eee solid;
            line-height: 30px;
            padding: 0 30px;
            font-size: 12px;
            color: #333;
            cursor: pointer;
        }

        .content .module .module-content ul li:last-child {
            border-bottom: none;
        }

        .content .module .module-content ul li:hover {
            background: #E7F4FD;
            color: #3F93EC;
        }

        .content .module .module-content ul li.active {
            background: #E7F4FD;
            color: #3F93EC;
        }

        .content .module .module-content .module-tabs {
            float: right;
            width: 80%;
        }

        .content .module .module-content .module-tabs > div {
            display: none;
            width: 100%;
        }

        .content .module .module-content .module-tabs .one:nth-of-type(1) {
            display: inline-block;
        }

        .content .module .module-content .module-tabs .one table {
            width: 100%;
        }

        .content .module .module-content .module-tabs .one table thead {
            background: #f4f4f4;
        }

        .content .module .module-content .module-tabs .one table thead tr th {
            padding: 10px 20px;
            border: 1px #eee solid;
            font-size: 12px;
        }

        .content .module .module-content .module-tabs .one table tbody tr td {
            border: 1px #eee solid;
            padding: 10px;
            font-size: 12px;
        }

        .content .module .module-content .module-tabs .one table tbody tr td span {
            margin: 0 4px;
        }

        .content .module .module-content .module-tabs .one table tbody tr td:last-child {
            color: #008DE7;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>

<div class="wrap">
    <div class="content">
        <div class="title">
            <div class="top_pages bottom_pages" style="float: right">
                <button class="layui-btn layui-btn-small" id="save">保存</button>
                <button style="margin-left: 24px" class="layui-btn layui-btn-primary layui-btn-small" id="return">取消</button>
            </div>
            <div class="title-role">
                <p>角色权限 / <?php xcho($roledata['data']['cn_name'])?></p>
            </div>
            <h2>基本信息</h2>
            <div class="row">
                <div class="col-xs-6">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">角色名称:</label>
                    <div class="col-sm-9">
                        <input class="form-control" disabled name="role_name" type="text"
                               value="<?php xcho($roledata['data']['cn_name'])?>" placeholder="角色名称">
                    </div>
                </div>
                <div class="col-xs-6">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">上级角色:</label>
                    <div class="col-sm-9">
                        <input class="form-control" disabled id="role-picker" name="group_id" type="text"
                               value="<?php xcho($roledata['data']['parent_name'])?>"
                               placeholder="上级角色">
                    </div>
                </div>
            </div>
        </div>
        <div class="module">
            <h3>模块权限</h3>
            <div class="module-content">
                <ul>
                    <?php foreach ($menu as $aData) { ?>
                        <li id="<?php xcho($aData['module_val']) ?>"><?php xcho($aData['module_name']) ?></li>
                    <?php } ?>
                </ul>
                <div class="module-tabs">
                    <?php foreach ($datalist as $mMKey => $aMData) { ?>
                        <div class="one  layui-form">
                            <table>
                                <thead>
                                <tr>
                                    <th>列表名称</th>
                                    <th>新增</th>
                                    <th>删除</th>
                                    <th>编辑</th>
                                    <th>查看</th>
                                    <th>其它</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($aMData as $mCKey => $aCData) { ?>
                                    <tr module="<?php xcho($mMKey) ?>" controller="<?php xcho($mCKey) ?>">
                                        <td><?php xcho($aCData['cname']) ?></td>
                                        <td>
                                            <?php if (array_key_exists('add',$aCData['data'])) { ?>
                                                <input lay-skin="primary" id="<?php xcho($aCData['data']['add']['pk']) ?>" type="checkbox"
                                                <?php if(array_key_exists($aCData['data']['add']['pk'],$actiondata)){
                                                    xcho('checked'.' ');
                                                    xcho('data-value='.$actiondata[$aCData['data']['add']['pk']]);
                                                }else{
                                                    xcho('data-value=');
                                                } ?>>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <?php if (array_key_exists('del',$aCData['data'])) { ?>
                                                <input lay-skin="primary" id="<?php xcho($aCData['data']['del']['pk']) ?>" type="checkbox"
                                                    <?php if(array_key_exists($aCData['data']['del']['pk'],$actiondata)){
                                                        xcho('checked'.' ');
                                                        xcho('data-value='.$actiondata[$aCData['data']['del']['pk']]);
                                                    }else{
                                                        xcho('data-value=');
                                                    } ?>>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <?php if (array_key_exists('edit',$aCData['data'])) { ?>
                                                <input lay-skin="primary" id="<?php xcho($aCData['data']['edit']['pk']) ?>" type="checkbox"
                                                    <?php if(array_key_exists($aCData['data']['edit']['pk'],$actiondata)){
                                                        xcho('checked'.' ');
                                                        xcho('data-value='.$actiondata[$aCData['data']['edit']['pk']]);
                                                    }else{
                                                        xcho('data-value=');
                                                    } ?>>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <?php if (array_key_exists('view',$aCData['data'])) { ?>
                                                <input lay-skin="primary" id="<?php xcho($aCData['data']['view']['pk']) ?>" type="checkbox"
                                                    <?php if(array_key_exists($aCData['data']['view']['pk'],$actiondata)){
                                                        xcho('checked'.' ');
                                                        xcho('data-value='.$actiondata[$aCData['data']['view']['pk']]);
                                                    }else{
                                                        xcho('data-value=');
                                                    } ?>>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <?php foreach ($aCData['data'] as $mAKey => $aAData) {?>
                                                <?php if ($mAKey != 'add' and $mAKey != 'del' and $mAKey != 'edit' and $mAKey != 'view') { ?>
                                                    <input lay-skin="primary" id="<?php xcho($aAData['pk']) ?>" type="checkbox"
                                                        <?php if(array_key_exists($aAData['pk'],$actiondata)){
                                                            xcho('checked'.' ');
                                                            xcho('data-value='.$actiondata[$aAData['pk']]);
                                                        }else{
                                                            xcho('data-value=');
                                                        } ?>>
                                                    <span><?php xcho($aAData['aname']) ?></span>
                                                <?php } ?>
                                            <?php }?>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" name="save" value="<?php xcho($save) ?>"/>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layer-v3.0.3/layer/layer.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script>
    $(function () {
        //切换选项卡
        $(".module-content>ul>li").click(function(){
            var ind=$(this).index();
            $(this).addClass("active").siblings("li").removeClass("active");
            $(".module-content>.module-tabs>div").eq(ind).slideDown(200).siblings("div").slideUp(200);
        })
        //返回列表页
        $("#return").on("click",function(){
            location.href = "/sysmanager/role_privilege/roleList"
        });
        //保存编辑内容
        $("#save").on("click",function () {
            var data = [];
            var ids = [];
            $('input[type="checkbox"]:checked').each(function () {
                var item = {};
                item.auth_key = $(this).attr("id");
                if($(this).attr("data-value") != ""){
                    item.id = $(this).attr("data-value");
                }
                data.push(item);
            });
            $('input[type="checkbox"]:not(:checked)').each(function () {
                if($(this).attr("data-value") != ""){
                    ids.push($(this).attr("data-value"));
                }
            });
//            debugger;
            var role_id = getUrlParam("id");

            $.ajax({
                url: $("input[name='save']").val(),
                data: {
                    role_id: role_id,
                    data: data,
                    ids: ids,
                },
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    if(data.success == 1){
                        layer.alert('保存成功!', {
                            skin: 'layui-layer-molv'
                        },function (){
                            location.reload();
                        });
                    }else{
                        layer.alert('保存失败！', {
                            skin: 'layui-layer-molv'
                        },function (){
                            location.reload();
                        });
                    }
                },
                complete:function(){

                },
                error: function () {

                }
            });
        })
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
    });
</script>
<?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>

<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
